# encoding: utf-8 -*-
import os

import yaml
import xlrd2
from get_project_path import project_path
from openpyxl import load_workbook

def load_yaml_file(filepath):
    # project_path获取该项目所在的位置
    with open(file=f'{project_path}{filepath}', mode='r', encoding='UTF-8') as f:
        yaml_content = yaml.load(f, Loader=yaml.FullLoader)
        return yaml_content

def read_excel(excelPath, sheetName="Sheet1"):
    # 读取excel表格的数据
    list_data=[]
    data = xlrd2.open_workbook(excelPath)
    table = data.sheet_by_name(sheetName)
    # 获取第一行作为key值
    keys = table.row_values(0)
    # 获取总行数
    rowNum = table.nrows
    print(rowNum)
    # 获取总列数
    colNum = table.ncols
    if rowNum <= 1:
        print("没有数据")
    else:
        for i in range(colNum):
            values = table.col_values(i,1)
            # n[keys[i]]=values  # 字典
            list_data.append(values)
    return list_data


if __name__ == '__main__':
    print(str(os.path))
    n = read_excel(r'D:\project\webautomate\data\112.xlsx')
    print(n)
    data = load_yaml_file('/data/train_addinformation.yml')['手机号和身份证']
    print(data)
